<template>
	<!-- 挤堵参数计算器 -->
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item label-width="350"
				:label-position="labelPosition" label="处理半径(m)" prop="radius">
				<u-input :border="border" placeholder="请输入处理半径" v-model="model.radius" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="处理层段有效厚度(m)" prop="thickness">
				<u-input :border="border" placeholder="请输入处理层段有效厚度" v-model="model.thickness" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="平均有效孔隙度" prop="porosity">
				<u-input :border="border" placeholder="请输入平均有效孔隙度" v-model="model.porosity" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="套管内径(m)" prop="innerDiameter">
				<u-input :border="border" placeholder="请输入套管内径" v-model="model.innerDiameter" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="预留灰面至处理层段底界长度(m)" prop="reservedLength">
				<u-input :border="border" placeholder="请输入预留灰面至处理层段底界长度" v-model="model.reservedLength" type="digit"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
				<u-form-item style="font-size: 22px;" :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="300"
					:label-position="labelPosition" label="堵剂用量" prop="dosage">
					<span v-if="model.dosage"> {{model.dosage}} m³ </span>
				</u-form-item>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">Q = kπ(R² - r²)hΦ + πr²H</view>
				<view class="u-item-desc">式中：Q— 堵剂用量，m³；K— 附加系数，1.1；R— 处理半径，m；h— 处理层段有效厚度，m；Φ— 平均有效孔隙度；r— 套管内径，m；H— 预留灰面至处理层段底界长度，m</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					radius: '',
					thickness: '',
					porosity: '',
					innerDiameter: '',
					reservedLength: '',
					dosage: ''
				},
				rules: {
					radius: [{
						required: true,
						message: '请输入处理半径',
						trigger: 'blur'
					}],
					thickness: [{
						required: true,
						message: '请输入处理层段有效厚度',
						trigger: 'blur'
					}],
					porosity: [{
						required: true,
						message: '请输入平均有效孔隙度',
						trigger: 'blur'
					}],
					innerDiameter: [{
						required: true,
						message: '请输入套管内径',
						trigger: 'blur'
					}],
					reservedLength: [{
						required: true,
						message: '请输入预留灰面至处理层段底界长度',
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,
				
			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						const R = parseFloat(this.model.radius);
						const h = parseFloat(this.model.thickness);
						const Φ = parseFloat(this.model.porosity);
						const r = parseFloat(this.model.innerDiameter);
						const H = parseFloat(this.model.reservedLength);
						const k = 1.1;
						
						// Q = kπ(R² - r²)hΦ + πr²H
						const Q = (k * Math.PI * (Math.pow(R, 2) - Math.pow(r, 2)) * h * Φ + Math.PI * Math.pow(r, 2) * H).toFixed(2);
						this.model.dosage = Q;
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
	}
</style>